﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace BallData
{
    class OddsInfo
    {
            
        public String mId;
        public String sId;
        public String oType;
        public String host;
        public String vs;
        public String visit;
        public String hostF;
        public String vsF;
        public String visitF;

        public DateTime chgTime;
        public OddsInfo()
        {
            mId = "";
            sId = "";
            oType = "";
            host = "";
            vs = "";
            visit = "";
            hostF = "";
            vsF = "";
            visitF = "";
        }
        public OddsInfo(String oddsinfo)
        {
            var infoArr = oddsinfo.Split(OddsUntil.SplitColumn);
            this.mId = infoArr[0];
            this.sId = infoArr[1];
            this.oType = infoArr[2];
            this.host = infoArr[3];
            this.vs = infoArr[4];
            this.visit = infoArr[5];
            this.hostF = infoArr[6];
            this.vsF = infoArr[7];
            this.visitF = infoArr[8];

            chgTime = DateTime.Now;
        }
        public String getOdds(int idx) 
        {
            if (idx == 1)
                return this.host;
            else if (idx == 2)
                return this.vs;
            else if (idx == 3)
                return this.visit;
            else if (idx == 4)
                return this.hostF;
            else if (idx == 5)
                return this.vsF;
            else if (idx == 6)
                return this.visitF;
            return "";

        }
        public void setOdds (int idx,String value) 
        {

            if (idx == 1)
                this.host = value;
            else if (idx == 2)
                this.vs = value;
            else if (idx == 3)
                this.visit = value;
            else if (idx == 4)
                this.hostF = value;
            else if (idx == 5)
                this.vsF = value;
            else if (idx == 6)
                this.visitF = value;

        }
        public void setChgOdds(OddsChg oddschg)
        {

            this.mId = oddschg.mId;
            this.sId = oddschg.sId;
            this.oType = oddschg.oType;
            this.host = oddschg.host;
            this.vs = oddschg.vs;
            this.visit = oddschg.visit;
            //this.hostF = oddschg;
            //this.vsF = infoArr[7];
            //this.visitF = infoArr[8];

        }
        public static String toJson(OddsInfo odds)
        {
            string json = JsonConvert.SerializeObject(odds);

            return json;
            
        }
        public static OddsInfo fromJson(String jsondata)
        {
            OddsInfo oddsinfo = JsonConvert.DeserializeObject<OddsInfo>(jsondata);

            return oddsinfo;
        }
    }
}
